package ChemBuddy;

/* Team Directories
 *
 * You are free to do whatever you want with this code. Frankly we don't give a damn.
 * 
 *  
 * Copyright GNU General Public License v3
 */

/**
 *
 * 
 */
import BuddyTemplate.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
        
public class Main implements StudyBuddy.RunnableBuddy{

    /**
     * @param args the command line arguments
     */
    
    String username;
    String user_doing_quiz;
    Integer thescore = new Integer(0);
    QuestionLayerCollection questions = new QuestionLayerCollection();
    
    public static void main(String[] args) {

    }
    
    public void run(){
        
        /* We Populate the QuestionCollection with questions*/
        thescore = SaveGame.score;
        user_doing_quiz = username;
        
        Question<String, String> testquestion = new Question<String, String>();
        testquestion.setQuestion("Given a orbital labeled by the quantum numbers: \n n = 3, l = 2, m(l) = 1, m(s) 1/2, \n How many planar nodes does it have?");
        testquestion.setDifficulty(0);
        testquestion.setChoice("3", false);
        testquestion.setChoice("2", true);
        testquestion.setChoice("1", false);
        //testquestion.setChoice("1/2", false);
        
        questions.addQuestion(testquestion);
        
        Question<String, String> testquestion2 = new Question<String, String>();
        testquestion2.setQuestion("Given the three elements F, S, CL, and Br.\n Which has the lowest ionization energy?");
        testquestion2.setDifficulty(0);
	testquestion2.setChoice("F", false);
        testquestion2.setChoice("S", false);
        testquestion2.setChoice("Br", false);
        testquestion2.setChoice("Cl", true);
        
        questions.addQuestion(testquestion2);
        
        
        Question<String, String> testquestion3 = new Question<String, String>();
        testquestion3.setQuestion("What is the electron configuration of Cr?");
        testquestion3.setDifficulty(0);
        testquestion3.setChoice("Cr: [Ar] 4s^2 3d^4", true);
        testquestion3.setChoice("Cr: 1s^2 2s^2 2p^6 3s^2 3p^6 4s^2 3p^4", false);
        testquestion3.setChoice("Cr: 1s^2 2s^2 2p^6 3s^2 3p^6 4s^2 3d^4", true);
        testquestion3.setChoice("Cr: [Ca] 3d^4", false);
        
        questions.addQuestion(testquestion3);
        
        Question<String, String> testquestion4 = new Question<String, String>();
        testquestion4.setQuestion("What is the Atomic number of Cu?");
        testquestion4.setDifficulty(0);
        testquestion4.setChoice("24", false);
        testquestion4.setChoice("29", true);
        testquestion4.setChoice("15", false);
        testquestion4.setChoice("6", false);
        
        questions.addQuestion(testquestion4);
        
        Question<String, String> testquestion5 = new Question<String, String>();
        testquestion5.setQuestion("What is the electron configuration of Fe 2+");
        testquestion5.setDifficulty(0);
	testquestion5.setChoice("Fe: [Ar] 3d^6", true);
        testquestion5.setChoice("Fe: [Ar] 4s^2 3d^4", false);
        testquestion5.setChoice("Fe: 1s^2 2s^2 2p^6 3s^2 3p^6 4s^2 3d^4", false);
        testquestion5.setChoice("Fe: 1s^2 2s^2 2p^6 3s^2 3p^6 3d^6", true);
       
        
        questions.addQuestion(testquestion5);
        
        
	Question<ImageIcon, String> testquestion6 = new Question<ImageIcon, String>();
	testquestion6.setQuestion(new ImageIcon(getClass().getResource( "/Picture/Chem01.jpg")));
        testquestion6.setDifficulty(1);
	testquestion6.setChoice("N", false);
        testquestion6.setChoice("P", true);
        testquestion6.setChoice("Se", false);
        testquestion6.setChoice("S", false);   

        questions.addQuestion(testquestion6);
        
	
	Question<String, String> testquestion7 = new Question<String, String>();
	testquestion7.setQuestion("Given a light of 350nm, how much photon energy, in J, does it emit?");
        testquestion7.setDifficulty(1);
	testquestion7.setChoice("41.8", false);
        testquestion7.setChoice("3.42*10^-4", false);
        testquestion7.setChoice("42", false);
        testquestion7.setChoice("3.4*10^-4", true);   

        questions.addQuestion(testquestion7);
        
	
	Question<String, String> testquestion8 = new Question<String, String>();
	testquestion8.setQuestion("If the elementary step A -> B has a reaction enthalpy of -70 kJ and an activation energy of 15kJ, the activation energy for the reverse step B-> A is:");
        testquestion8.setDifficulty(1);
	testquestion8.setChoice("85", true);
        testquestion8.setChoice("75", false);
        testquestion8.setChoice("55", false);
        testquestion8.setChoice("65", false);   

        
	questions.addQuestion(testquestion8);
        
	Question<String, String> testquestion9 = new Question<String, String>();
	testquestion9.setQuestion("The reaction of nitrogen dixoide with water yields:");
        testquestion9.setDifficulty(1);
	testquestion9.setChoice("HNO3", false);
        testquestion9.setChoice("NH3 and O2", false);
        testquestion9.setChoice("NO and 2OH", true);
        testquestion9.setChoice("NO and OH", false);   

        questions.addQuestion(testquestion9);
        
	Question<String, String> testquestion10 = new Question<String, String>();
	testquestion10.setQuestion("A radioactive substance have a half life of 19.6 hours, how much of the substance will be remain after 50 hours if there is 100g to begin:");
        testquestion10.setDifficulty(1);
	testquestion10.setChoice("17.1", false);
        testquestion10.setChoice("17.0", true);
        testquestion10.setChoice("18.5", false);
        testquestion10.setChoice("18.4", false);
	
	questions.addQuestion(testquestion10);

	Question<String, String> testquestion11 = new Question<String, String>();
	testquestion11.setQuestion("Which have the longer wavelength given the same kinetic energy, an electron or a proton?");
        testquestion11.setDifficulty(2);
	testquestion11.setChoice("The electon, due to a smaller mass", true);
        testquestion11.setChoice("The electon, due to a bigger mass", false);
        testquestion11.setChoice("The proton, due to a bigger mass", false);
        testquestion11.setChoice("The proton, due to a small mass", false);
	
	questions.addQuestion(testquestion11);

	Question<String, String> testquestion12 = new Question<String, String>();
	testquestion12.setQuestion("Which of the following is the pH of a solution obtained by mixing 50.0mL of 0.200M HA and 50.0mL of 0.200M NaOH?" +
	"\n I. Neutral if HA is a strong acid \n II. Basic if HA is a weak acid \n III. Neutral if HA is a weak acid");
        testquestion12.setDifficulty(2);
	testquestion12.setChoice("I, II, and III", false);
        testquestion12.setChoice("I and III", false);
        testquestion12.setChoice("II and III", false);
        testquestion12.setChoice("I and II", true);
	
	questions.addQuestion(testquestion12);

	Question<String, String> testquestion13 = new Question<String, String>();
	testquestion13.setQuestion("Calculate the change in energy in kJ per mole for atoms that emit light at a wavelength of 486nm");
        testquestion13.setDifficulty(2);
	testquestion13.setChoice("2.46*10^2 kJ", false);
        testquestion13.setChoice("1.57*10^2 kJ", false);
        testquestion13.setChoice("-2.46*10^2 kJ", true);
        testquestion13.setChoice("-1.57*10^2 kJ", false);
	
	questions.addQuestion(testquestion13);

	Question<String, ImageIcon> testquestion14 = new Question<String, ImageIcon>();
	testquestion14.setQuestion("Given the following molecules and ions: NF3, what is the molecular shape?");
        testquestion14.setDifficulty(2);
	testquestion14.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ14a.JPG")), false);
        testquestion14.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ14b.JPG")), false);
        testquestion14.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ14c.JPG")), true);
        testquestion14.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ14d.JPG")), false);
	
	questions.addQuestion(testquestion14);

	Question<String, ImageIcon> testquestion15 = new Question<String, ImageIcon>();
	testquestion15.setQuestion("Which of the following is the correct lewis structore of PO4 3-?");
        testquestion15.setDifficulty(2);
	testquestion15.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ15a.JPG")), false);
        testquestion15.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ15b.JPG")), true);
        testquestion15.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ15c.JPG")), true);
        testquestion15.setChoice(new ImageIcon(getClass().getResource( "/Picture/ChemQ15d.JPG")), false);
	
	questions.addQuestion(testquestion15);
        
        
       
        
        // This is the rather inelegant pieces of code which get the Ball Rolling
   
        // First we increase the state of the question - we request the nextquestion 

        if (user_doing_quiz.equals(username)){
            System.out.println("The score is " + SaveGame.score);
            thescore = SaveGame.score;
            
        }
        
        else {
            System.out.println("Setting the score to Zero");
            thescore = 0;
            
        }
        
        Question thenextquestion = questions.nextQuestion();
        
        // Now depending on what question the first question is, we launch the appopriate window
        // Note that this same bit of code is also used in PictureFrame, PictureChoiceFrame, etc
        
        // We get the instance of the choice of the first method
        if(thenextquestion.choices.get(0) instanceof String && thenextquestion.getQuestion() instanceof String){
            QuestionFrame nextQuestion = new QuestionFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
                
        else if(thenextquestion.choices.get(0) instanceof ImageIcon && thenextquestion.getQuestion() instanceof String){
            PictureFrame nextQuestion = new PictureFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
                
        else if(thenextquestion.choices.get(0) instanceof String && thenextquestion.getQuestion() instanceof ImageIcon){
            PictureChoiceFrame nextQuestion = new PictureChoiceFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
        
        
    }
    
    public String getName(){
        
        return "Chem01 Buddy";
        
    }
    
    public int getScore(){
       
        return SaveGame.score;
        
    }
    
    public void setLoginInfo(String theusername){
        
        username = theusername;
        
    }
    
    
    public Serializable getSavedGame(){
        
        return new SaveGame();
        
    }
    
    public void loadSavedGame(Serializable savegame){
        
        thescore = ((SaveGame)savegame).score;
        
    }
    
    

    

}
